package com.zmcn.fileTransfer.fw.action;

import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 会话拦截器
 * 
 * @author 欧建东
 * @email oyjd@163.com
 * 
 */
public class AuthorizationInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6338933709326212120L;
	private static Log log = LogFactory.getLog(AuthorizationInterceptor.class);

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		printPara(invocation);
		return invocation.invoke();
	}

	/**
	 * 开发参数查看
	 * 
	 * @param invocation
	 */
	@SuppressWarnings("rawtypes")
	private void printPara(ActionInvocation invocation) {
		try {
			HttpServletRequest req = (HttpServletRequest) invocation.getInvocationContext().get(StrutsStatics.HTTP_REQUEST);
			String reqUrl = req.getRequestURL().toString();
			StringBuffer sb = new StringBuffer("\r\n[").append(req.getRemoteHost()).append("]request-->").append(reqUrl);
			Map map = req.getParameterMap();
			for (Iterator item = map.keySet().iterator(); item.hasNext();) {
				String key = (String) item.next();
				for (String v : (String[]) map.get(key)) {
					sb.append("\r\n------para->").append(key).append("=").append(v);
				}
			}
			log.info(sb.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
